home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / mplus_1.exe / PUSHDEMO.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  3KB  |  92 lines

  1. /*--------------------------------------------------------------
  2.  *  File:           PUSHDEMO.C
  3.  *  Description:    This program illustrates how to create a
  4.  *                  3-D push button for use with a mouse.
  5.  *
  6.  *  This demo developed for the MPLUS Graphic Interface Library.
  7.  *-------------------------------------------------------------*/
  8.  
  9. #include <stdio.h>
  10. #include <graph.h>
  11.  
  12. #include "gplus.h"
  13. #include "gscreen.h"
  14. #include "mouser.h"
  15.  
  16. main()
  17. {
  18.     int quit, ch, device;
  19.     struct ms_status ms_status;
  20.     GWDW *groot;
  21.     GWDW *gwpush;
  22.     GWDW *gwquit;
  23.  
  24.     mpsetvideomode( _ERESCOLOR );
  25.  
  26.     if( ms_reset() == 0 )
  27.     {
  28.         printf("\nMouse driver not loaded.\n");
  29.         mpsetvideomode( _DEFAULTMODE );
  30.         exit(1);
  31.     }
  32.     ms_setevent(1);             /* enable mouse interrupt trapping */
  33.     ms_showcursor();
  34.  
  35.     /*      Open our background window as a "root" window to conserve
  36.      *      memory.
  37.      */
  38.     groot = groottopen( 10, 20, 16, 50, _GFILLINTERIOR, BRIGHTWHITE, GREY );
  39.     _settextposition( 5, 1 );
  40.     outtext( "Click left mouse button", BRIGHTWHITE, -1 );
  41.  
  42.     /*      This is our "push" button.
  43.      */
  44.     gwpush = gwdwtopen( 11, 25, 13, 32, _GRAISE, BLACK, WHITE );
  45.     outtext( " PUSH", BLACK, -1 );
  46.  
  47.     /*      Here's another push button used to quit this demo.
  48.      */
  49.     gwquit = gwdwtopen( 11, 40, 13, 47, _GRAISE, BLACK, WHITE );
  50.     outtext( " QUIT", BLACK, -1 );
  51.  
  52.     quit = 0;
  53.     while( !quit )
  54.     {
  55.         device = dev_ready( &ch, &ms_status );
  56.         if( device == _MS )
  57.         {
  58.             /*      Got some mouse input...
  59.              */
  60.             if( (ms_status.condmask & _LBPRESSED) ||
  61.                 (ms_status.condmask & _LBRELEASED) )
  62.             {
  63.                 /*      according to mask, left button was pushed
  64.                  *      or released.  Use ginwindow() to determine
  65.                  *      which button the mouse was pointing to.
  66.                  */
  67.                 if( ginwindow( gwpush, ms_status.x, ms_status.y ) )
  68.                     physhighlite( gwpush->x1, gwpush->y1, gwpush->x2, gwpush->y2);
  69.                 else if( ginwindow( gwquit, ms_status.x, ms_status.y ) )
  70.                 {
  71.                     /*      mouse was on "quit" button.  Use physhighlite()
  72.                      *      to "press" button down.
  73.                      */
  74.                     physhighlite( gwquit->x1, gwquit->y1, gwquit->x2, gwquit->y2 );
  75.                     quit = 1;
  76.                 }
  77.             }
  78.         } /* end if( device == _MS ) */
  79.     } /* end while( !quit ) */
  80.  
  81.     /*      Clean up.
  82.      */
  83.     ms_reset();
  84.     gwdwclose( gwpush );
  85.     gwdwclose( gwquit );
  86.     grootclose( groot );
  87.     mpsetvideomode( _DEFAULTMODE );
  88. }
  89.  
  90.  
  91.  
  92.